/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.utils;

/**
 * DEBUG
 * 
 * @author huangmy
 * @date   2008-8-26
 */
public class DebugUtil {
	/**
	 * 当前线程堆栈
	 * 
	 */
    public static String printCurrentStackTrace() {
    	String t = "";
    	StackTraceElement[] stes = Thread.currentThread().getStackTrace();
    	if (stes != null) {
    		for (StackTraceElement ste : stes) {
    			if (ste.getFileName() == null) {
    				continue;
    			}
    			
    			String s = ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" 
				          + ste.getLineNumber() + ")";
    			t = t + s + "\n";
    		}
    	}
    	
    	System.out.println(t); 
    	
    	return t;
    }
    
    /**
     * 显示堆栈
     * 
     * @param stes
     * @return
     */
    public static String getCurrentStackTrace(StackTraceElement[] stes) {
    	StringBuffer b = new StringBuffer();
    	if (stes != null) {
    		for (StackTraceElement ste : stes) {
    			if (ste.getFileName() == null) {
    				continue;
    			}
    			
    			b.append("\t");
    			b.append(ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":" 
    					+ ste.getLineNumber() + ")");
    			b.append("\n");
    		}
    	}
    	
    	return b.toString();
    }
}
